package com.tsxy.mall.service.impl;

import com.tsxy.mall.entity.Book;
import com.tsxy.mall.entity.BookSort;
import com.tsxy.mall.mapper.BookMapper;
import com.tsxy.mall.mapper.BookSortMapper;
import com.tsxy.mall.service.BookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.AutoPopulatingList;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    Logger logger = LoggerFactory.getLogger("bookServiceImpl");
    @Resource
    BookSortMapper bookSortMapper;
    @Resource
    BookMapper bookMapper;

    @Override
    public List<Book> getBooksByParentSortId(Integer id) {
        List<Integer> ids = bookSortMapper.selectChildren(id);
        if (ids == null || ids.size() == 0){
            return null;
        }else {
            return bookMapper.selectInSort( ids);
        }
    }

    @Override
    public List search(Book book, Integer firstSortId) {
        return bookMapper.search(book,firstSortId);
    }

    @Override
    public Book selectById(Integer id) {
        return bookMapper.selectById(id);

    }

    @Override
    public List getBySortId(Integer sortId) {
        return bookMapper.getByBookSort(sortId);
    }

    @Override
    public List getBookByFirstId(Integer firstSortId) {
        List<Book> books = getBooksByParentSortId(firstSortId);
        return books;
    }
}
